<%@ page contentType="text/html;charset=utf-8" language="java"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<html:html>
<head>
<script type="text/javascript" src="jobSchedule/Bs_Misc.lib.js"></script>
<script type="text/javascript" src="jobSchedule/Bs_DataGrid.class.js"></script>
<script src=js/dialog.js" language="JavaScript" type="text/javascript"></script>
<script src=js/prototype-1.4.0.js" language="JavaScript" type="text/javascript"></script>
<link rel='stylesheet' href='jobSchedule/style1.css'>		
<title>CGProject</title>
<html:base/>
<%
	String cpath=request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+cpath+"/";
%>
	<script src="<%=basePath %>js/dialog.js" language="JavaScript" type="text/javascript"></script>
	<script src="<%=basePath %>js/prototype-1.4.0.js" language="JavaScript" type="text/javascript"></script>
</head>
<script type="text/javascript">
	
	function replaceState(originalData)
	{
		originalData = originalData.replace(/HasInput/g,"<table width='100%' height='100%' bgcolor='#cecece'><tr><td class='bsDg_table'><bean:message key='HasInput'/></td></tr></table>");
		originalData = originalData.replace(/HasAssigned/g,"<table width='100%' height='100%' bgcolor='#eafbcc'><tr><td class='bsDg_table'><bean:message key='HasAssigned'/></td></tr></table>");
		originalData = originalData.replace(/WaitingConfirm/g,"<table width='100%' height='100%' bgcolor='#fef0dd'><tr><td class='bsDg_table'><bean:message key='WaitingConfirm'/></td></tr></table>");
		originalData = originalData.replace(/ConfirmNotPassed/g,"<table width='100%' height='100%' bgcolor='#93a491'><tr><td class='bsDg_table'><bean:message key='ConfirmNotPassed'/></td></tr></table>");
		originalData = originalData.replace(/ConfirmPassed/g,"<table width='100%' height='100%' bgcolor='#f0e2f9'><tr><td class='bsDg_table'><bean:message key='ConfirmPassed'/></td></tr></table>");
		originalData = originalData.replace(/Finished/g,"<table width='100%' height='100%' bgcolor='#fbf8cc'><tr><td class='bsDg_table'><bean:message key='Finished'/></td></tr></table>");
		originalData = originalData.replace(/StandBy/g,"<table width='100%' height='100%' bgcolor='#c3dbff'><tr><td class='bsDg_table'><bean:message key='StandBy'/></td></tr></table>");
		originalData = originalData.replace(/IsDoing/g,"<table width='100%' height='100%' bgcolor='#d43e1b'><tr><td class='bsDg_table'><bean:message key='IsDoing'/></td></tr></table>");
		originalData = originalData.replace(/PAUSE/g,"<table width='100%' height='100%' bgcolor='#ff001b'><tr><td class='bsDg_table'><bean:message key='PAUSE'/></td></tr></table>");
		return originalData;
	}	
	var data = new Array();
</script>

<logic:iterate id="element1" name="Link_Schedule">

<script type="text/javascript">
  var dataString = "<bean:write name="element1" />";
	
	dataString = replaceState(dataString);
	
	data[data.length] = dataString.split("$");
  var headerNum = 0;
</script>
</logic:iterate>
<script type="text/javascript">

function init() {
  myGrid = new Bs_DataGrid('myGrid');
  myGrid.bHeaderFix = false;
  myGrid.rowClick = new Object( {key:0, baseUrl:'detail.do?Type=<bean:write name="Type"/>&ObjectID='} );
  var header = new Array();
  var headerString = "<bean:write name="UnitHeader" />";  
  header = headerString.split("$");
  headerNum = header.length;
  myGrid.useNoDataText=true;
  myGrid.setHeaderProps(header);
  myGrid.setData(data);
  myGrid.drawInto('myGridDiv'); 
  
  myGrid.orderByColumn(0);
  
  
}

function showUnit(a)
{	

	var b = a.substr( a.indexOf("?")+1);
	top.B.location.href="<%=basePath%>frame.do?Frame=12&Id="+getBID( )+"&"+b;
	<logic:notEmpty name="ManagerFlag">
	openWindow(a,300,headerNum*25,'');
	</logic:notEmpty>
}

 function getBID( ) {  
    
     var query = top.B.location.search.substring(1);     // Get query string  
     var pairs = query.split("&");                 // Break at ampersand  
     for(var i = 0; i < pairs.length; i++) {  
         var pos = pairs[i].indexOf('=');          // Look for "name=value"  
         if (pos == -1) continue;                  // If not found, skip  
         var argname = pairs[i].substring(0,pos);  // Extract the name  
         var value = pairs[i].substring(pos+1);    // Extract the value  
         value = decodeURIComponent(value);        // Decode it, if needed  
         if (argname=="Id")                        // Choose "Id"    
     		return value;
     }  
     return "16";                                    // Not exist ,return preview
 }

	var xhr = false ;
	function createXHR(){
	
  		 try {
    		 xhr = new XMLHttpRequest();
  		 } 
  		 catch (trymicrosoft) {
  		   try {
  		     xhr = new ActiveXObject("Msxml2.XMLHTTP");
 		    } 
 		    catch (othermicrosoft) {
 		      try {
 		        xhr = new ActiveXObject("Microsoft.XMLHTTP");
 		      }
 		       catch (failed) {
 		        xhr = false;
 		      }  
  		   }
 		  }
 		  if (!xhr)
  		   alert("Error initializing XMLHttpRequest!");

	}
	function queryUnit(unitId){
		var date = new Date();
		
		createXHR();
		xhr.open("GET","<%=basePath %>jobSchedule/queryUnit.do?Type=<bean:write name='Type'/>&ObjectID="+unitId+"&Date="+date.getTime());
		xhr.send(null);
		xhr.onreadystatechange=handleReadyState;
		
	}
	function handleReadyState(){
		if(xhr.readyState==4){
			if(xhr.status==200){
				parseResult();					
			}
		}
	}
	function parseResult(){
		var unitDataString = replaceState(xhr.responseText);
		var unitData = unitDataString.split("$");
		
		for (i = 0; i<myGrid._data.length;i++)
		{
			if ( myGrid._data[i][0]== unitData[0] ){
			 unitData[1] = "<font color=red>"+unitData[1]+"</font>"
			 myGrid._data[i] = unitData;
			}
		}
		myGrid.drawInto('myGridDiv'); 
	}

</script>

<body onLoad="init();">
<div style="  overflow-y:   scroll;   height:   100%;   width:   100%;">
<div id="myGridDiv" style="width:100% height:100%; overflow:auto"></div>


</body>
</html:html>

